<template>
    <div class="card-page">
        <tool-bar nav="" title="Es映射">
            <el-button size="small" @click="save_index_click" type="primary">1创建索引</el-button>
            <el-button size="small" @click="save_mapping_click" type="primary">2创建映射</el-button>
        </tool-bar>
        <el-row :gutter="12" type="flex">
            <el-col :span="12">
                <kv label="EsUrl">
                    <el-input v-model="info.url" chk="*"/>
                </kv>
            </el-col>
            <el-col :span="12">
                <kv label="索引名称">
                    <el-input v-model="info.name" chk="*"/>
                </kv>
            </el-col>
        </el-row>
        <div>
            mapping
        </div>

        <el-input type="textarea" v-model="info.content" :autosize="{ minRows: 15, maxRows: 30 }"/>
    </div>
</template>

<script type="text/ecmascript-6" setup>




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"info":{}});
const info = $computed(()=> $data.info );

const $props = defineProps({
    id: { type: String } ,
    action: { type: String }
});

const action_name = $computed(()=>{
    return {add: "添加", edit: "修改"}[$props.action]
});



const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);



const save_index_click = function() {
//校验
    if (jv.chk_main() == false) {
        return;
    }
    jv.$saveData("info",$data.info)
    jv.$http.post("/admin/es/index", $data.info).then(res => {
//[axios拦截器中已处理了异常]。
        jv.info("创建成功");
    })
};
const save_mapping_click = function() {
//校验
    if (jv.chk_main() == false) {
        return;
    }
    if (this.$findByBindExpression("info.content").chk_item("*") == false) {
        return;
    }
    jv.$saveData("info",$data.info)
    jv.$http.post("/admin/es/mapping", $data.info).then(res => {
//[axios拦截器中已处理了异常]。
        jv.info("创建成功");
    })
};

onMounted( function() {
    jv.$loadData("info", v=> $data.info = v )
})



</script>

<style scoped lang="scss">
textarea {
    width: 100%;
    height: 80vh;
    font-family: Microsoft Yahei, Arail, Tabhoma;
    line-height: 1.8;
}
</style>
